package com.lanyou.esb.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.lanyou.cook.common.DefaultDateJsonSerializer;
import com.lanyou.cook.entity.domain.FieldSystem;

/**
 * 
 * @author ly-zengzugen
 *
 */

@Entity
@EntityListeners({ AuditingEntityListener.class })
@Table(name = "T_ESB_BU_IF_ALARM")
// 还没有增加监听
public class IfAlarm {

	private String id;// 接口报警表id
	private String ifId;// 接口id
	private String ifType;// 接口类型
	private String ifName;// 接口名字
	private String fieldId;// 系统
	private String systemCode;// 系统编号
	private String alarmType;// 报警类型
	private String alarmLevel;// 报警等级
	private Date inEsbTime;// 进去esb时间
	private Date outEsbTime;// 离开essb时间
	private Date platReqDate;// 平台发送请求时间
	private Date platResDate;// 平台接收请求时间
	private int flow;// 请求量
	private float answerTime;// 响应时间
	private int reqThreshold;// 请求阀值
	private Date errorDate;// 发生时间
	private String errorReceiver;// 错误接收者
	private String assignWorkCode;// 工单号
	/** 是否可用 **/
	private String isEnable;
	private String creator;
	private String modifier;
	private Date createTime;
	private Date modifyTime;

	/** http响应码 **/
	private String resCode;
	/** 请求来源 **/
	private String reqIp;
	/** 请求方式 **/
	private String reqMethod;
	/** 请求URL **/
	private String reqUrl;
	/** 请求报文 **/
	private String reqMess;
	/** 告警点峰值 **/
	private float peakValue=0;
	/** 重复次数 **/
	private int repeat = 0;
	public final static Specification<IfAlarm> EmptySpecification = new Specification<IfAlarm>() {
		@Override
		public Predicate toPredicate(Root<IfAlarm> root,
				CriteriaQuery<?> query, CriteriaBuilder cb) {
			return null;
		}
	};

	public static Specification<IfAlarm> idSpecification(String id) {
		return new Specification<IfAlarm>() {
			@Override
			public Predicate toPredicate(Root<IfAlarm> root,
					CriteriaQuery<?> query, CriteriaBuilder cb) {
				query.where(cb.equal(root.get("id"), id));
				return null;
			}
		};
	}

	@Id
	@GeneratedValue(generator = "uuidGenerator")
	@GenericGenerator(name = "uuidGenerator", strategy = "uuid")
	@Column(name = "IF_ALARM_ID", length = 36)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(name = "IF_ID", length = 36)
	public String getIfId() {
		return ifId;
	}

	public void setIfId(String ifId) {
		this.ifId = ifId;
	}

	@Column(name = "IF_TYPE", length = 2)
	public String getIfType() {
		return ifType;
	}

	public void setIfType(String ifType) {
		this.ifType = ifType;
	}

	@Column(name = "IF_NAME", length = 50)
	public String getIfName() {
		return ifName;
	}

	public void setIfName(String ifName) {
		this.ifName = ifName;
	}

	@Column(name = "FIELD_SYSTEM_ID", length = 50)
	public String getFieldId() {
		return fieldId;
	}

	public void setFieldId(String fieldId) {
		this.fieldId = fieldId;
	}

	@Column(name = "SYSTEM_CODE", length = 50)
	public String getSystemCode() {
		return systemCode;
	}

	public void setSystemCode(String systemCode) {
		this.systemCode = systemCode;
	}

	@Column(name = "ALARM_TYPE", length = 2)
	public String getAlarmType() {
		return alarmType;
	}

	public void setAlarmType(String alarmType) {
		this.alarmType = alarmType;
	}

	@Column(name = "ALARM_LEVEL", length = 2)
	public String getAlarmLevel() {
		return alarmLevel;
	}

	public void setAlarmLevel(String alarmLevel) {
		this.alarmLevel = alarmLevel;
	}

	@Column(name = "IN_ESB_DATE")
	@JsonSerialize(using = DefaultDateJsonSerializer.class)
	public Date getInEsbTime() {
		return inEsbTime;
	}

	public void setInEsbTime(Date inEsbTime) {
		this.inEsbTime = inEsbTime;
	}

	@Column(name = "OUT_ESB_DATE")
	@JsonSerialize(using = DefaultDateJsonSerializer.class)
	public Date getOutEsbTime() {
		return outEsbTime;
	}

	public void setOutEsbTime(Date outEsbTime) {
		this.outEsbTime = outEsbTime;
	}

	@Column(name = "PLATFORM_REQUEST_DATE")
	@JsonSerialize(using = DefaultDateJsonSerializer.class)
	public Date getPlatReqDate() {
		return platReqDate;
	}

	public void setPlatReqDate(Date platReqDate) {
		this.platReqDate = platReqDate;
	}

	@Column(name = "PLATFORM_RESPONSE_DATE")
	@JsonSerialize(using = DefaultDateJsonSerializer.class)
	public Date getPlatResDate() {
		return platResDate;
	}

	public void setPlatResDate(Date platResDate) {
		this.platResDate = platResDate;
	}

	@Column(name = "FLOW")
	public int getFlow() {
		return flow;
	}

	public void setFlow(int flow) {
		this.flow = flow;
	}

	@Column(name = "ANSWER_TIMES")
	public float getAnswerTime() {
		return answerTime;
	}

	public void setAnswerTime(float answerTime) {
		this.answerTime = answerTime;
	}

	@Column(name = "FLOW_THRESHOLD")
	public int getReqThreshold() {
		return reqThreshold;
	}

	public void setReqThreshold(int reqThreshold) {
		this.reqThreshold = reqThreshold;
	}

	@Column(name = "ERROR_DATE")
	@JsonSerialize(using = DefaultDateJsonSerializer.class)
	public Date getErrorDate() {
		return errorDate;
	}

	public void setErrorDate(Date errorDate) {
		this.errorDate = errorDate;
	}

	@Column(name = "ERROR_RECEIVER", length = 50)
	public String getErrorReceiver() {
		return errorReceiver;
	}

	public void setErrorReceiver(String errorReceiver) {
		this.errorReceiver = errorReceiver;
	}

	@Column(name = "ASSIGN_WORK_CODE", length = 50)
	public String getAssignWorkCode() {
		return assignWorkCode;
	}

	public void setAssignWorkCode(String assignWorkCode) {
		this.assignWorkCode = assignWorkCode;
	}

	@Column(name = "IS_ENABLE", length = 2)
	public String getIsEnable() {
		return isEnable;
	}

	public void setIsEnable(String isEnable) {
		this.isEnable = isEnable;
	}

	@CreatedBy
	@Column(length = 50, updatable = false)
	public String getCreator() {
		return creator;
	}

	public void setCreator(String creator) {
		this.creator = creator;
	}

	@LastModifiedBy
	@Column(length = 50)
	public String getModifier() {
		return modifier;
	}

	public void setModifier(String modifier) {
		this.modifier = modifier;
	}

	@Column(name = "CREATED_DATE", updatable = false)
	@JsonSerialize(using = DefaultDateJsonSerializer.class)
	@CreatedDate
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Column(name = "LAST_UPDATED_DATE")
	@JsonSerialize(using = DefaultDateJsonSerializer.class)
	@LastModifiedDate
	public Date getModifyTime() {
		return modifyTime;
	}

	public void setModifyTime(Date modifyTime) {
		this.modifyTime = modifyTime;
	}

	@Column(name = "RESPONSE_CODE", length = 4)
	public String getResCode() {
		return resCode;
	}

	public void setResCode(String resCode) {
		this.resCode = resCode;
	}

	@Column(name = "REQUEST_IP", length = 16)
	public String getReqIp() {
		return reqIp;
	}

	public void setReqIp(String reqIp) {
		this.reqIp = reqIp;
	}

	@Column(name = "REQUEST_METHOD", length = 10)
	public String getReqMethod() {
		return reqMethod;
	}

	public void setReqMethod(String reqMethod) {
		this.reqMethod = reqMethod;
	}

	@Column(name = "REQUEST_URL", length = 50)
	public String getReqUrl() {
		return reqUrl;
	}

	public void setReqUrl(String reqUrl) {
		this.reqUrl = reqUrl;
	}

	@Column(name = "REQUEST_MESSAGE", length = 500)
	public String getReqMess() {
		return reqMess;
	}

	public void setReqMess(String reqMess) {
		this.reqMess = reqMess;
	}

	@Column(name = "ALARM_PEAK_VALUE")
	public float getPeakValue() {
		return peakValue;
	}

	public void setPeakValue(float peakValue) {
		this.peakValue = peakValue;
	}

	@Column(name = "IF_ALARM_REPEAT")
	public int getRepeat() {
		return repeat;
	}

	public void setRepeat(int repeat) {
		this.repeat = repeat;
	}

}